package com.fast.fastenjoy.components.sys.action;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.fast.fastenjoy.base.web.action.BaseAction;
import com.fast.fastenjoy.components.sys.manager.RandomValidateCodeManager;

@Controller
@RequestMapping
public class RandomValidateCodeAction extends BaseAction{

	private static final long serialVersionUID = -2853431924805791436L;
	
	@Autowired
	private RandomValidateCodeManager randomValidateCodeManager;
	
	/**
	 * 刷新注册验证码
	 */
	@RequestMapping("/refVerifyCode")
	public void refVerifyCode(){
		
		String id = getParameter("id");
		
		toRenderedImage(randomValidateCodeManager.getRandcodeImg(id, getRequest(), getResponse()));
	}
	
	/**
	 * 验证注册验证码
	 */
	@RequestMapping("/checkVerifyCode")
	public void checkVerifyCode(){
		
		String verifyCode = getParameter("param");
		String id = getParameter("id");
		
		boolean isOk = randomValidateCodeManager.verifyRandCode(id, verifyCode, getRequest());
		
		Map<String, Object> map = new HashMap<String, Object>();
		
		if(isOk){
			map.put("info", "验证码正确");
			map.put("status", "y");
		}else{
			map.put("info", "验证码错误");
			map.put("status", "n");
		}
		
		toJson(map);
	}
	
}
